﻿// -----------------------------------------------------------------------
// <copyright file="OrderdFilter.cs" company="FCIS">
// TODO: Update copyright text.
// </copyright>
// -----------------------------------------------------------------------

namespace IP_Package.Operations.Restoration.RemoveNoise
{
    using System;
    using System.Collections.Generic;
    using System.Drawing;
    using System.Linq;
    using System.Text;
    using IP_Package.Operations.Neighbor_operations;
    using IPPackage.ImageOperation; 

    /// <summary>
    /// TODO: Update summary.
    /// </summary>
    public class OrderdFilter : Operation
    {
        /// <summary>
        /// Applies the max filter.
        /// </summary>
        /// <param name="maskSize">Size of the mask.</param>
        /// <param name="orignalImg">The orignal img.</param>
        /// <returns>the new bitmap image</returns>
        public Bitmap ApplyMaxFilter(int maskSize, Color[,] orignalImg)
        {
            LinearConvolution convObj = new LinearConvolution();
            convObj.BufferOfImage = orignalImg;
            this.BufferOfImage = orignalImg;
            Color[,] buffer = convObj.AddBorder(maskSize);
            Bitmap resultImg = convObj.LinearConvolutionOrderdFilterFn(buffer, maskSize, "Max");
            this.NewBufferOfImage = convObj.NewBufferOfImage;
            return resultImg;
        }

        /// <summary>
        /// Applies the min filter.
        /// </summary>
        /// <param name="maskSize">Size of the mask.</param>
        /// <param name="orignalImg">The orignal img.</param>
        /// <returns>the new bitmap image</returns>
        public Bitmap ApplyMinFilter(int maskSize, Color[,] orignalImg)
        {
            LinearConvolution convObj = new LinearConvolution();
            convObj.BufferOfImage = orignalImg;
            this.BufferOfImage = orignalImg;
            Color[,] buffer = convObj.AddBorder(maskSize);
            Bitmap resultImg = convObj.LinearConvolutionOrderdFilterFn(buffer, maskSize, "Min");
            this.NewBufferOfImage = convObj.NewBufferOfImage;
            return resultImg;
        }

        /// <summary>
        /// Applies the median filter.
        /// </summary>
        /// <param name="maskSize">Size of the mask.</param>
        /// <param name="orignalImg">The orignal img.</param>
        /// <returns>the new bitmap image</returns>
        public Bitmap ApplyMedianFilter(int maskSize, Color[,] orignalImg)
        {
            LinearConvolution convObj = new LinearConvolution();
            convObj.BufferOfImage = orignalImg;
            this.BufferOfImage = orignalImg;
            Color[,] buffer = convObj.AddBorder(maskSize);
            Bitmap resultImg = convObj.LinearConvolutionOrderdFilterFn(buffer, maskSize, "Median");
            this.NewBufferOfImage = convObj.NewBufferOfImage;
            return resultImg;
        }

        /// <summary>
        /// Applies the midpoint filter.
        /// </summary>
        /// <param name="maskSize">Size of the mask.</param>
        /// <param name="orignalImg">The orignal img.</param>
        /// <returns>the new bitmap image</returns>
        public Bitmap ApplyMidpointFilter(int maskSize, Color[,] orignalImg)
        {
            LinearConvolution convObj = new LinearConvolution();
            convObj.BufferOfImage = orignalImg;
            this.BufferOfImage = orignalImg;
            Color[,] buffer = convObj.AddBorder(maskSize);
            Bitmap resultImg = convObj.LinearConvolutionOrderdFilterFn(buffer, maskSize, "Midpoint");
            this.NewBufferOfImage = convObj.NewBufferOfImage;
            return resultImg;
        }

        /// <summary>
        /// Applies the adaptive median filter.
        /// </summary>
        /// <param name="maskSize">Size of the mask.</param>
        /// <param name="orignalImg">The orignal img.</param>
        /// <returns>the new bitmap image</returns>
        public Bitmap ApplyAdaptiveMedianFilter(int maskSize, Color[,] orignalImg)
        {
            LinearConvolution convObj = new LinearConvolution();
            convObj.BufferOfImage = orignalImg;
            this.BufferOfImage = orignalImg;
            Color[,] buffer = convObj.AddBorder(maskSize);
            Bitmap resultImg = convObj.LinearConvolutionOrderdFilterFn(buffer, maskSize, "Adaptive Median");
            this.NewBufferOfImage = convObj.NewBufferOfImage;
            return resultImg;
        }
    }
}
